#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define maxn 15
#define inf 0x3fffffff
int S, B, N;
struct Perket
{
    int acid;
    int sweet;
    Perket(int a = 0, int s = 0) : acid(a), sweet(s){};
};
Perket arr[maxn];
int vis[maxn], bestans = inf, f[maxn];
void dfs(int x, int totalAcid, int totalSweet)
{
    for (int i = x; i <= N; ++i)
    {
        if (vis[i] == 0)
        {
            int acid = arr[i].acid;
            int sweet = arr[i].sweet;
            if (abs(totalSweet - totalAcid) > 0)
            {
                acid *= totalAcid;
                sweet += totalSweet;
            }
            bestans = min(bestans, abs(acid - sweet));
            vis[i] = 1;
            dfs(i, acid, sweet);
            vis[i] = 0;
        }
    }
}
int main()
{
    cin >> N;
    for (int i = 1; i <= N; ++i)
    {
        cin >> S >> B;
        arr[i].acid = S, arr[i].sweet = B;
    }
    dfs(1, 0, 0);
    cout << bestans << endl;
    return 0;
}